package entityMapping.demo3.bean;


import entityMapping.demo3.enums.LiveTradingType;

import java.util.Calendar;
import java.util.TimeZone;

public class Default {
    private String user = "default";
    private String account = "default";
    private String market = "FX";
    private String currency = "USD";
    private String accountPrefix = "A";
    private double accountCash = 100000.0;
    private double marginTimes = 40.0;
    private double marginCut = 100000;
    private double commission = 0.0;
    private double commissionMin = 0.0;
    private TimeZone timeZone; // 以前就留的，没有真的在用，也不要再使用
    private double orderQuantity = 100000;
    private double positionStopLoss = 1000.0;
    private double marginCall = 0.95;
    private int settlementDays = 0;

    private double stopLossPercent = 0.2;
    private double freezePercent = 0.2;
    private double terminatePercent = 0.2;

    private double companyStopLossValue = 0;
    private double freezeValue = 0;
    private double terminateValue = 0;

    private boolean liveTrading = false;
    private boolean userLiveTrading = false;
    private LiveTradingType liveTradingType = LiveTradingType.DEFAULT;
    private double creditPartial = 0.0;
    private String appSetting = "";
    private double reservedBuyingPowerPercentage = 0;
    private double marginCutAmount = 0;

    public static Default getInstance(
            String user,
            String account,
            String market,
            String currency,
            boolean liveTrading,
            double freezeValue,
            double terminateValue,
            double freezePercent,
            double terminatePercent,
            String appSetting) {

        Default d = new Default();

        d.user = user;
        d.account = account;
        d.market = market;
        d.currency = currency;
        d.liveTrading = liveTrading;
        d.freezeValue = freezeValue;
        d.terminateValue = terminateValue;
        d.freezePercent = freezePercent;
        d.terminatePercent = terminatePercent;
        d.appSetting = appSetting;
        return d;
    }

    public static Default getInstance(
            String user,
            String account,
            String market,
            String currency,
            String accountPrefix,
            double accountCash,
            double marginTimes,
            double marginCut,
            double commission,
            double commissionMin,
            TimeZone timeZone,
            double orderQuantity,
            double positionStopLoss,
            double marginCall,
            int settlementDays,
            double stopLossPercent,
            double freezePercent,
            double terminatePecent,
            boolean liveTrading,
            boolean userLiveTrading,
            double companyStopLossValue,
            double freezeValue,
            double terminateValue,
            LiveTradingType liveTradingType,
            double creditPartial,
            String appSetting) {
        return getInstance(user, account, market, currency, accountPrefix, accountCash, marginTimes, marginCut, commission,
                commissionMin, timeZone, orderQuantity, positionStopLoss, marginCall, settlementDays, stopLossPercent,
                freezePercent, terminatePecent, liveTrading, userLiveTrading, companyStopLossValue, freezeValue,
                terminateValue, liveTradingType, creditPartial, appSetting, 0, 0);
    }

    public static Default getInstance(
            String user,
            String account,
            String market,
            String currency,
            String accountPrefix,
            double accountCash,
            double marginTimes,
            double marginCut,
            double commission,
            double commissionMin,
            TimeZone timeZone,
            double orderQuantity,
            double positionStopLoss,
            double marginCall,
            int settlementDays,
            double stopLossPercent,
            double freezePercent,
            double terminatePecent,
            boolean liveTrading,
            boolean userLiveTrading,
            double companyStopLossValue,
            double freezeValue,
            double terminateValue,
            LiveTradingType liveTradingType,
            double creditPartial,
            String appSetting,
            double reservedBuyingPowerPercentage,
            double marginCutAmount) {

        Default d = new Default();

        d.user = user;
        d.account = account;
        d.market = market;
        d.currency = currency;
        d.accountPrefix = accountPrefix;
        d.accountCash = accountCash;
        d.marginTimes = marginTimes;
        d.marginCut = marginCut;
        d.commission = commission;
        d.commissionMin = commissionMin;
        d.timeZone = timeZone;
        d.orderQuantity = orderQuantity;
        d.positionStopLoss = positionStopLoss;
        d.marginCall = marginCall;
        d.settlementDays = settlementDays;
        d.stopLossPercent = stopLossPercent;
        d.freezePercent = freezePercent;
        d.terminatePercent = terminatePecent;
        d.liveTrading = liveTrading;
        d.userLiveTrading = userLiveTrading;
        d.companyStopLossValue = companyStopLossValue;
        d.freezeValue = freezeValue;
        d.terminateValue = terminateValue;
        d.liveTradingType = liveTradingType;
        d.creditPartial = creditPartial;
        d.appSetting = appSetting;
        d.reservedBuyingPowerPercentage = reservedBuyingPowerPercentage;
        d.marginCutAmount = marginCutAmount;

        return d;
    }

    public String getUser() {
        return user;
    }

    public String getAccount() {
        return account;
    }

    public String getMarket() {
        return market;
    }

    public String getCurrency() {
        return currency;
    }

    public String getAccountPrefix() {
        return accountPrefix;
    }

    public double getAccountCash() {
        return accountCash;
    }

    public double getMarginTimes() {
        return marginTimes;
    }

    public double getCommission() {
        return commission;
    }

    public TimeZone getTimeZone() {
        return timeZone;
    }

    public Calendar getCalendar() {
        Calendar cal = Calendar.getInstance();
        if (timeZone != null)
            cal.setTimeZone(this.getTimeZone());

        return cal;
    }

    public double getOrderQuantity() {
        return orderQuantity;
    }

    public double getPositionStopLoss() {
        return positionStopLoss;
    }

    public double getMarginCall() {
        return marginCall;
    }

    public double getCommissionMin() {
        return commissionMin;
    }

    public double getCommission(double value) {
        return Math.max(commissionMin, value * commission);
    }

    public double getMarginCut() {
        return marginCut;
    }

    public int getSettlementDays() {
        return settlementDays;
    }

    public double getStopLossPercent() {
        return stopLossPercent;
    }

    public double getFreezePercent() {
        return freezePercent;
    }

    public double getTerminatePercent() {
        return terminatePercent;
    }

    public boolean isLiveTrading() {
        return liveTrading;
    }

    public boolean isUserLiveTrading() {
        return userLiveTrading;
    }

    public double getCompanyStopLossValue() {
        return companyStopLossValue;
    }

    public double getTerminateValue() {
        return terminateValue;
    }

    public double getFreezeValue() {
        return freezeValue;
    }

    public LiveTradingType getLiveTradingType() {
        return liveTradingType;
    }

    public double getCreditPartial() {
        return creditPartial;
    }

    public String getAppSetting() {
        return appSetting;
    }

    public double getReservedBuyingPowerPercentage() {
        return reservedBuyingPowerPercentage;
    }

    public double getMarginCutAmount() {
        return marginCutAmount;
    }
}
